# Contributor: Curt Tilmes <Curt.Tilmes@nasa.gov>
# Maintainer: Curt Tilmes <Curt.Tilmes@nasa.gov>
pkgname=rakudo
pkgver=2024.04
pkgrel=0
pkgdesc="Compiler for the Raku programming language"
url="https://rakudo.org/"
# ppc64le/s390x/riscv64 blocked by moarvm
arch="all !ppc64le !s390x !riscv64"
license="Artistic-2.0"
depends="nqp~$pkgver"
makedepends="perl-utils moarvm-dev~$pkgver"
checkdepends="perl-test-harness"
subpackages="$pkgname-dev $pkgname-doc"
source="https://github.com/rakudo/rakudo/releases/download/$pkgver/rakudo-$pkgver.tar.gz"

build() {
	perl Configure.pl --prefix=/usr --backends=moar \
		--rakudo-home=/usr/share/"$pkgname"
	make -j"$JOBS"
}

check() {
	# Failed 1 out of 42 subtests - Non-zero exit:
	# "Dubious, test returned 1 (wstat 256, 0x100)"
	# in t/06-telemetry/01-basic.t. These 3 archs
	# also take about half an hour to finish building,
	# skipping tests will make things a little faster.
	# When running tests in parallel, the test
	# t/02-rakudo/15-gh_1202.t also starts failing
	# on armhf with the same "wstat 256" message.
	case $CARCH in
	arm*|x86)
		./rakudo-m -V
		;;
	*)
		export RAKUDO_RUN_TIMING_TESTS=0
		export ROAST_TIMING_SCALE=15
		export TEST_JOBS=$JOBS
		export HARNESS_VERBOSE=1

		msg "Running $TEST_JOBS parallel test jobs"
		make test
		;;
	esac
}

package() {
	make DESTDIR="$pkgdir" install
	ln -sv rakudo "$pkgdir"/usr/share/perl6

	install -Dvm644 CONTRIBUTING.md CREDITS \
		LICENSE README.md VERSION \
		-t "$pkgdir"/usr/share/doc/"$pkgname"
	cp -vr docs "$pkgdir"/usr/share/doc/"$pkgname"/
}

dev() {
	default_dev
	amove	usr/bin/perl6-debug* usr/bin/perl6-gdb-m \
		usr/bin/perl6-lldb-m usr/bin/perl6-valgrind-m \
		usr/bin/rakudo-debug* usr/bin/rakudo-gdb-m \
		usr/bin/rakudo-lldb-m usr/bin/rakudo-valgrind-m \
		usr/bin/raku-debug

	mkdir -vp "$subpkgdir"/usr/share/"$pkgname"
	cp -vr "$builddir"/tools "$subpkgdir"/usr/share/"$pkgname"/
}

sha512sums="
98b4dd35456df1774a320dbd53ffecc72323d91c260ce1264b2056624e8cdf8a47cfcd89b775411f8bf3fb1f1b4725e2b75c7724c5891a4d366e5ba3f2a11cd4  rakudo-2024.04.tar.gz
"
